package com.kakarote.core.entity;

import cn.hutool.core.util.StrUtil;
import com.aliyun.openservices.ons.api.PropertyKeyConst;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.Properties;


@ConfigurationProperties(prefix = "wk.mq")
@Getter
@Setter
public class MqProperties {

    private String type;

    /**
     * mq账号
     */
    private String accessKey;

    /**
     * mq密码
     */
    private String secretKey;

    /**
     * mq地址
     */
    private String nameSrvAddr;

    /**
     * mq topic
     */
    private String topic;

    /**
     * mq groupId
     */
    private String groupId;

    /**
     * mq 消费线程数
     */
    private Integer consumeThreadNums;

    /**
     * mq 消息发送超时时间
     */
    private Integer sendMsgTimeoutMillis;


    public Properties getProperties() {
        Properties properties = new Properties();
        properties.setProperty(PropertyKeyConst.AccessKey, this.accessKey);
        properties.setProperty(PropertyKeyConst.SecretKey, this.secretKey);
        properties.setProperty(PropertyKeyConst.NAMESRV_ADDR, this.nameSrvAddr);
        if (StrUtil.isNotBlank(this.groupId)) {
            properties.setProperty(PropertyKeyConst.GROUP_ID, this.groupId);
        }
        if (this.consumeThreadNums != null) {
            properties.setProperty(PropertyKeyConst.ConsumeThreadNums, String.valueOf(this.consumeThreadNums));
        }
        if (this.sendMsgTimeoutMillis != null) {
            properties.setProperty(PropertyKeyConst.SendMsgTimeoutMillis, String.valueOf(this.sendMsgTimeoutMillis));
        } else {
            properties.setProperty(PropertyKeyConst.SendMsgTimeoutMillis, "5000");
        }
        return properties;
    }
}
